require('../css/commCss/normalize.css')
require('../css/commCss/reset.css')
require('../css/commCss/property.css')
require('../css/commCss/basic.css')

// 本身样式
require('../css/motionIntroduce.less')

// 字体
require('../libs/fonts/iconfont.css')

//axios请求
const axios = require('axios')


// weui-插件库
require('weui')
const weui = require('weui.js')



// 文档加载事件
document.addEventListener('DOMContentLoaded',function(){
    

    /**
     * 1.返回
     */
    document.querySelector('#return').addEventListener('click',function(){
        history.go(-1)
    })

    /**
     * 2.发请求获取数据
     */

    let cid = sessionStorage.cid

    axios.get('http://139.9.177.51:8099/sports/courseDetail/?id='+cid)
    .then(function(res){
        // console.log(res.data.data);
        let data =  res.data.data;
        // console.log(data.fragments);

        // 视频
        document.querySelector('video').src ="http://139.9.177.51:8099" + data.fragments[0].videoUrl


        document.querySelector('#name').textContent = data.name//标题
        document.querySelector('#calorie').textContent = data.calorie//千卡
        document.querySelector('#time').textContent = data.time//时间
        document.querySelector('#peoplenum').textContent = data.peoplenum//练过
        document.querySelector('#imgurl').src ="http://139.9.177.51:8099" + data.imgurl//练过
        document.querySelector('#frequency').textContent = data.frequency//频次
        document.querySelector('#instrument').textContent = data.instrument//器材
        document.querySelector('#desc').textContent = data.desc//


        //将视频信息存入会话存储
        sessionStorage.fragments = JSON.stringify(data.fragments)
        

    })


    /**
     * 教练用户
     */
    let userId = sessionStorage.cid
    // console.log(userId);
    axios.get('http://139.9.177.51:8099/users/accountinfo/?userId=' + userId)
    .then(function(res){
        // console.log(res.data.data);
        let data = res.data.data
        //教练用户
        document.querySelector('#nickname').textContent = data.nickname
        document.querySelector('#sign').textContent = data.sign
    })



    /**
     * 点击视频
     */

    /**
     * 3.更多
     * 点击更多展开
     */
    document.querySelector('#moerBtn').addEventListener('click',function(){
        document.querySelector('#desc').style.display = 'block'
        document.querySelector('#moerBtn').style.display = 'none';
    })


    /**
     * 4.点击开始训练，跳转页面
     */
     document.querySelector('#StartBtn').addEventListener('click',function(){
        location.href = './motionTrain2.html'
    })


    /**
     * 5.点击关注
     */
    let followBtn = document.querySelector('#followBtn')
    followBtn.addEventListener('click',function(){
        if (followBtn.textContent === "已关注") {
            weui.toast('已关注', 1000)
        } else {
            followBtn.style.backgroundColor = '#fff'
            followBtn.style.color = '#ccc'
            followBtn.textContent = '已关注'
            weui.toast('关注成功', 1000)
        }
    })







})